home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 23 code / Documentary Synchronicity ƒ / Source ƒ / Support ƒ / About.c next >
Encoding:
C/C++ Source or Header  |  1995-06-10  |  3.9 KB  |  149 lines  |  [TEXT/KAHL]

  1. /* 4567890123456789012345678901234567890123456789012345678901234567 */
  2. /*
  3.  * File:              About.c
  4.  * Author:            Mark H. Linton
  5.  * Creation Date:     2/4/95
  6.  * Modification Date: 
  7.  * Description:       A routine which may be used to handle the 
  8.  *                    "About <application name>" item in the apple
  9.  *                    menu.
  10.  */
  11. #include <Dialogs.h>
  12. #include <Resources.h>
  13. #include <TextEdit.h>
  14. #include <Memory.h>
  15.  
  16. #include "About.h"
  17. #include "Toolbox.h"
  18.  
  19. pascal Boolean DialogEventFilter(DialogPtr aDialog, 
  20.     EventRecord *anEvent, short *anItem);
  21.  
  22. Rect theTextPaneRect;
  23. TEHandle theTextPane;
  24.  
  25. void DoAbout(short anIdentifier) {
  26.     DialogPtr theDialog;
  27.     short theItem, itemCount;
  28.     Boolean done = false;
  29.     short theType;
  30.     Handle theHandle;
  31.     Rect theRect;
  32.     Handle theText;
  33.     StScrpHandle theStyle;
  34.     GrafPtr theCurrentPort;
  35.     short theItemHit;
  36.     long theLastLine;
  37.     short theTextHeight, thePaneHeight;
  38.  
  39.     theDialog = GetNewDialog(anIdentifier, nil, kInFront);
  40.     if (theDialog != nil) {
  41.         GetPort(&theCurrentPort);
  42. #if STRICT_WINDOWS
  43.         SetPortWindowPort(theDialog);
  44. #else
  45.         SetPort(theDialog);
  46. #endif
  47. #define kTextPane 3
  48.         GetDialogItem(theDialog, kTextPane, &theType, &theHandle, 
  49.             &theTextPaneRect);
  50.         theTextPane = TEStyleNew(&theTextPaneRect, &theTextPaneRect);
  51.         theStyle = (StScrpHandle)GetResource('styl', anIdentifier);
  52.         theText = GetResource('TEXT', anIdentifier);
  53.         HLock(theText);
  54.         TEStyleInsert(*theText, GetHandleSize(theText), theStyle, 
  55.             theTextPane);
  56.         HUnlock(theText);
  57.         theLastLine = (**theTextPane).nLines;
  58.         theTextHeight = TEGetHeight(theLastLine, 1, theTextPane);
  59.         thePaneHeight = theTextPaneRect.bottom - theTextPaneRect.top;
  60.         (**theTextPane).destRect.bottom = 
  61.             (**theTextPane).destRect.top + theTextHeight - thePaneHeight;
  62.         (void)SetDialogDefaultItem(theDialog, ok);
  63.         (void)SetDialogCancelItem(theDialog, ok);
  64.         (void)SetDialogTracksCursor(theDialog, true);
  65. #if STRICT_WINDOWS
  66.         ShowWindow(GetDialogWindow(theDialog));
  67. #else
  68.         ShowWindow(theDialog);
  69. #endif
  70.         DrawDialog(theDialog);
  71.         SetEventMask(everyEvent);
  72.         do {
  73.             ModalDialog((ModalFilterProcPtr)DialogEventFilter, 
  74.                 &theItemHit);
  75.         } while (theItemHit != ok && theItemHit != cancel);
  76. #if STRICT_WINDOWS
  77.         HideWindow(GetDialogWindow(theDialog));
  78. #else
  79.         HideWindow(theDialog);
  80. #endif
  81.         itemCount = CountDITL(theDialog);
  82.         for (theItem = 1; theItem <= itemCount; theItem++) {
  83.             GetDialogItem(theDialog, theItem, 
  84.                 &theType, &theHandle, &theRect);
  85.             if ((theType == picItem) || 
  86.                     (theType == (picItem + itemDisable))) {
  87.                 ReleaseResource(theHandle);
  88.             }
  89.         }
  90.         DisposeDialog(theDialog);
  91.         SetPort(theCurrentPort);
  92.     }
  93. }
  94.  
  95. pascal Boolean DialogEventFilter(DialogPtr aDialog, 
  96.         EventRecord *anEvent, short *anItem) {
  97.     GrafPtr theCurrentPort;
  98.     ModalFilterProcPtr StandardFilter;
  99.     Boolean eventWasHandled;
  100.     static long theLastTime = 0;
  101.     long theTime = TickCount();
  102. #define kTicksToWait 10
  103. #define kQuickTicksToWait 0
  104.     long ticksToWait = kTicksToWait;
  105.     
  106.     GetPort(&theCurrentPort);
  107. #if STRICT_WINDOWS
  108.     SetPortWindowPort(aDialog);
  109. #else
  110.     SetPort(aDialog);
  111. #endif
  112.     switch (anEvent->what) {
  113.     case updateEvt:
  114. #if STRICT_WINDOWS
  115.         if ((WindowRef)anEvent->message == (WindowRef)aDialog) {
  116.             BeginUpdate(GetDialogWindow(aDialog));
  117.             UpdateDialog(aDialog, GetWindowPort(GetDialogWindow(aDialog))->visRgn);
  118. #else
  119.         if ((WindowPtr)anEvent->message == aDialog) {
  120.             BeginUpdate(aDialog);
  121.             UpdateDialog(aDialog, aDialog->visRgn);
  122. #endif
  123.             TEUpdate(&theTextPaneRect, theTextPane);
  124. #if STRICT_WINDOWS
  125.             EndUpdate(GetDialogWindow(aDialog));
  126. #else
  127.             EndUpdate(aDialog);
  128. #endif
  129.         }
  130.         break;
  131.     default:
  132.         if ((anEvent->modifiers & optionKey) == 0) {
  133.             ticksToWait = kTicksToWait;
  134.         } else {
  135.             ticksToWait = kQuickTicksToWait;
  136.         }
  137.         if (theTime > (theLastTime + ticksToWait)) {
  138.             TEScroll(0, -1, theTextPane);
  139.             theLastTime = theTime;
  140.         }
  141.         break;
  142.     }
  143.     if (GetStdFilterProc(&StandardFilter) == noErr) {
  144.         eventWasHandled = StandardFilter(aDialog, anEvent, anItem);
  145.     }
  146.     SetPort(theCurrentPort);
  147.     return eventWasHandled;
  148. }
  149.